package com.shuaiche.yeguan.ui.login;

import android.content.Context;
import android.content.Intent;

import com.geetest.onelogin.OneLoginHelper;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by baoyinbo on 2017/10/26.
 * 登录帮助工具类
 */
public class SCLoginWrapHelper {

    public static boolean login = false;

    public static void setLogin(Boolean isLogin) {
        login = isLogin;
    }

    /**
     * 当session过期防止多个请求同时或很短时间内触发
     * 开启2个登录页面
     */
    private static int isFirstBack = 1;

    public static void starLogintActivity(Context context) {
        if (isFirstBack == 1) {
            isFirstBack = 3;

            if (OneLoginHelper.with().isPreGetTokenResultValidate()) {
                Intent intent = new Intent(context, OneLoginDialogStyleActivity.class);
                context.startActivity(intent);
            } else {
                Intent intent = new Intent(context, LoginActivity.class);
                context.startActivity(intent);
            }

            //开启一个异步线程，当用户超过两秒没有再次点击返回键，则取消退出状态
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    isFirstBack = 1; // 取消退出
                }
            }, 3000);
        }
    }


}
